package mop.exception;

import mop.model.task.Task;


/**
 * Exception class to be thrown when business rule 2 is violated
 * 
 * @author	 MOP Team 7
 */

public class BusinessRule3Exception extends Throwable
{


	/**
	 * Initializes an BusinessRule3Exception with the problematic task
	 * 
	 * @param task	The problematic task
	 *  
	 * @effect Sets the task
	 * 	|this.setTask(task);
	 */
	public BusinessRule3Exception(Task t)
	{
		this.setTask(t);
	}
	
	
	/**
	 * Return a error message that can be used by the GUI
	 * 
	 * @return An error message describing the incorrect name
	 */
	public String toString()
	{
		StringBuffer sb = new StringBuffer();
		sb.append("BusinessRule 3 has been violated !! \n");
		sb.append("BusinessRule 3 states that if the start date of a task is in the future, than the task's state is either Failed or Unfinished \n");
		sb.append("If the deadline date of a task is in the past, than the task's state is either Failed or Succesful \n");
		
		sb.append("The violation was triggered by the following task : ");
		sb.append(this.t.getId());
		sb.append("\n with following state = "+t.getStatus().toString());
		return sb.toString();
	}
	
	 /**
	  * Set the task
	  * 
	  * @param t	The problematic task
	  *  
	  * @post The task is set to the passed one
	  * |this.t ==  t
	  */
	 private void setTask(Task t) 
	 {
		 this.t = t;
	 }
	 
	 /**
	  * Returns the task
	  * @return task t
	  */
	 public Task getTask() 
	 {
		 return this.t;
	 }
	
	/**
	 * weird java demand
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * the problematic task
	 */
	private Task t;
		
	

}
